#include <cstdio>
#include <algorithm>
using namespace std;
struct node{
    int data;
    struct node *lchild, *rchild;
    int height;//记录当前节点的高度，空间换时间
    node()
    {//利用构造函数在创建创建新节点时进行初始化
        //当然这个初始化对于这道题目来说可能是多余的，不过，这确实是一个良好的编码习惯
        data = 0;
        lchild = rchild = NULL;
        height = 1;
    }
};
int getHeight(node *nod)
{
    if(NULL == nod) return 0;
    else return nod->height;
}
void updateHeight(node* nod)
{
    nod->height = max(getHeight(nod->lchild), getHeight(nod->rchild)) + 1;
}
int getFactor(node *nod)
{//返回值大于1或者小于-1说明需要做平衡调整
    return getHeight(nod->lchild) - getHeight(nod->rchild);
}
//每次进行平衡调整之后，都需要更新节点的高度
void rotateRight(node*& nod)
{
    node* tmp = nod->lchild;
    nod->lchild = tmp->rchild;
    tmp->rchild = nod;
    updateHeight(nod);
    updateHeight(tmp);
    nod = tmp;
}
void rotateLeft(node*& nod)
{
    node* tmp = nod-> rchild;
    nod->rchild = tmp->lchild;
    tmp->lchild = nod;
    updateHeight(nod);
    updateHeight(tmp);
    nod = tmp;
}
void insert(node*& root, node* newnode)
{
    if(NULL == root) root = newnode;
    else {
        int factor;
        if(newnode->data < root->data) insert(root->lchild, newnode);
        else insert(root->rchild, newnode);
        updateHeight(root);
        factor = getFactor(root);
        if (2 == factor)
        { //LL or LR
            factor = getFactor(root->lchild);
            if (1 == factor)
            { //LL
                rotateRight(root);
            }
            else
            { //LR
                rotateLeft(root->lchild);
                rotateRight(root);
            }
            }else if(-2 == factor)
            {//RR or RL
                factor = getFactor(root->rchild);
                if(-1 == factor)
                {//RR
                    rotateLeft(root);
                }else
                {//RL
                    rotateRight(root->rchild);
                    rotateLeft(root);
                }
            }
    }
}
int main()
{
    node* root = NULL;
    int num;
    scanf("%d", &num);
    while(num--)
    {
        node *nod = new node();
        scanf("%d", &nod->data);
        insert(root, nod);
    }  
    printf("%d\n", root->data);
}